package org.leaf.green.b2b

class PurchaseDetail {

    Purchase purchase
    String serialNumber
    Dealer dealer
    Product product
    BigDecimal quantity
    BigDecimal price
    BigDecimal amount
    String unit

    static belongsTo = [purchase : Purchase]

    String toString(){
        return "${purchase.serialNumber}-${serialNumber}"
    }

    static constraints = {
        purchase(nullable:false)
        serialNumber(nullable:false, blank:false, unique : 'purchase', maxSize : 3)
        dealer(nullable:false)
        product(nullable:false)
        quantity(nullable:false, min : new BigDecimal(0))
        price(nullable:false, min : new BigDecimal(0))
        amount(nullable:false, min : new BigDecimal(0))
        unit(nullable:false, blank:false, maxSize : 4)
    }

    static mapping = {
        table 'B2B_PURCHASE_DETAIL'
    }
}
